home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacHack 1996
/
MacHack 1996.toast
/
Hacks
/
Hacks ’87
/
Source ƒ.sit
/
Source ƒ
/
C ƒ
/
fastalert.c
Wrap
Text File
|
1987-03-24
|
5KB
|
195 lines
/* fastalert.c version 1.0 March 20, 1987.
This file contains four routines in Lightspeed C v2.01 to provide a
more effecient way to display alert boxes.
The four routines are named FastAlert, FastNoteAlert, FastStopAlert and
FastCautionAlert. They are functionally equivelant to and have the same
interface as the system traps Alert, NoteAlert, StopAlert and CautionAlert
respectively. When the fast alert routines are called, the image of the
screen under the alert box is saved. When they return, the screen image
is instantly restored and no update event is generated.
Since I wrote them mainly for my own use, I choosed a simple but not
the best approach.
The basic algrithem (FastShowAlert) is as follows:
1. Calls GetResource to get the alert template from resource file.
2. Calculates the boundary rectangle of the alert box from its resource
template.
3. Copies the screen image under the alert box to a temporary bit map.
4. Calls one of the normal alert routine.
5. Restores the screen image.
6. Walks down the WindowList and empties the updateRgn field of all
window records on the list.
7. Returns the value returned by the normal alert routine.
This method has a major shortcomming. Since it calls SetEmptyRgn to
empty the update region of all windows on the WindowList, all pending
update events are also lost. In other words, if your program generates an
update event and it calls one of the fast alert routines before it gets
to the main event loop, that update event will not be serviced.
Nevertheless, these routines have been very useful for me and I'd like to
share them with you. Please send me suggestions, comments and bug reports
to the address listed below or to GEnie mail "S.WANG".
Written by: Sidney Wang
Department of Computer Science
University of Montana
Missoula, MT 59812
Note: Some of the bitmap manipulation statements are borrowed from
Mike Schuster, "Try Pop-Up Menus", The Best of MacTutor, PP 218-225.
*/
#include <QuickDraw.h>
#include <DialogMgr.h>
#include <MemoryMgr.h>
#include <stdio.h>
extern WindowPeek WindowList : 0x9D6; /* Low memory global */
FastAlert( alertID, filterProc )
/* This routine is functionally equivelant to Alert. */
int alertID;
ProcPtr filterProc;
{
return ( FastShowAlert( 0, alertID, filterProc ) );
}
/* ---------------------------------------- */
FastNoteAlert( alertID, filterProc )
/* This routine is functionally equivelant to NoteAlert. */
int alertID;
ProcPtr filterProc;
{
return ( FastShowAlert( 1, alertID, filterProc ) );
}
/* ---------------------------------------- */
FastStopAlert( alertID, filterProc )
/* This routine is functionally equivelant to StopAlert. */
int alertID;
ProcPtr filterProc;
{
return ( FastShowAlert( 2, alertID, filterProc ) );
}
/* ---------------------------------------- */
FastCautionAlert( alertID, filterProc )
/* This routine is functionally equivelant to CautionAlert. */
int alertID;
ProcPtr filterProc;
{
return ( FastShowAlert( 3, alertID, filterProc ) );
}
/* ---------------------------------------- */
FastShowAlert( alertType, alertID, filterProc )
int alertType;
int alertID;
ProcPtr filterProc;
{
typedef AlertTemplate **AlertHandle;
AlertHandle theAlert;
BitMap **theAlertBits;
BitMap *alertBits;
int rowBytes;
int rows;
Rect alertRect;
GrafPtr wMngPort;
int resultCode;
WindowPeek wTempPtr;
/* Get the alert template from resource file */
if ( (theAlert = (AlertHandle) GetResource( 'ALRT', alertID )) == NULL )
{
return; /* Alert template not in resource file */
}
alertRect = (*theAlert)->boundsRect;
/* Enlarge the rectangle to cover the border of an alert box */
InsetRect( &alertRect, -8, -8 );
rowBytes = ((alertRect.right - alertRect.left + 15) >> 4) << 1;
rows = alertRect.bottom - alertRect.top;
/* Allocate spece for temporary bit map */
theAlertBits = (BitMap **)
NewHandle( rowBytes * rows + (long) sizeof(BitMap) );
if ( !theAlertBits )
{
return; /* Out of memory, just return */
}
HLock( theAlertBits ); /* Now it's save to dereference handle */
alertBits = *theAlertBits;
/* Construct bit map */
alertBits->baseAddr = (char *) (alertBits + 1);
alertBits->rowBytes = rowBytes;
alertBits->bounds = alertRect;
GetWMgrPort( &wMngPort );
/* Save screen bits under the alert box */
CopyBits( &wMngPort->portBits, alertBits, &alertBits->bounds,
&alertBits->bounds, 0, 0L );
switch ( alertType )
{
case 0 : resultCode = Alert( alertID, filterProc ); break;
case 1 : resultCode = NoteAlert( alertID, filterProc ); break;
case 2 : resultCode = StopAlert( alertID, filterProc ); break;
case 3 : resultCode = CautionAlert( alertID, filterProc ); break;
}
/* Restore screen bits */
CopyBits( alertBits, &wMngPort->portBits, &alertBits->bounds,
&alertBits->bounds, 0, 0L );
HUnlock( theAlertBits );
DisposHandle( theAlertBits );
/* Empty the update regions of all windows */
wTempPtr = WindowList;
while ( wTempPtr != NULL )
{
SetEmptyRgn( wTempPtr->updateRgn );
wTempPtr = wTempPtr->nextWindow;
}
return( resultCode );
} /* FastShowAlert */